import { BASE_URL } from '../../apis/requests.js';
//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    gridCol:3,
    iconList: [{
      icon: 'cardboardfill',
      color: 'red',
      badge: 120,
      name: '证(解)绑定'
    }, {
      icon: 'recordfill',
      color: 'orange',
      badge: 1,
      name: '图书检索'
    }, {
      icon: 'picfill',
      color: 'yellow',
      badge: 0,
      name: '个人资料'
    }, {
      icon: 'noticefill',
      color: 'olive',
      badge: 22,
      name: '预约查询'
    }, {
      icon: 'timefill',
      color: 'cyan',
      badge: 0,
      name: '借阅历史'
    }, {
      icon: 'hotfill',
      color: 'blue',
      badge: 0,
      name: '热门图书'
    }, {
      icon: 'discoverfill',
      color: 'purple',
      badge: 0,
      name: '借书状态'
    }, {
      icon: 'questionfill',
      color: 'mauve',
      badge: 0,
      name: '帮助'
    }, {
      icon: 'commandfill',
      color: 'purple',
      badge: 0,
      name: '关于'
    }, {
      icon: 'brandfill',
      color: 'mauve',
      badge: 0,
      name: '版权'
    }]
  },

  bindNavToNextPage(e) {
    let clickIndex = e.currentTarget.dataset['index'];
    const tokenLength = wx.getStorageSync('token').toString().length
    switch (clickIndex) {
      case 0:
        // 如果用户未登录
        if (tokenLength === 0) {
          wx.navigateTo({
            url: '../login/login',
          })
        } else {
          //TODO: 已经登录，点击后退出登录，登录状态设置为false
          wx.showModal({
            title: "提示",
            content: "确定退出登录吗？",
            success(res) {
              if (res.confirm) {
                wx.setStorageSync('token', "")
              }

            }
          })
        }
        break
      case 1:
        if (tokenLength === 0) {
          wx.showModal({
            title: "提示",
            content: "请先登录！"
          })
        } else {
          wx.navigateTo({
            url: '../getBooksBy/getBooksBy',
          })
        }
        break
      case 2:
        if (tokenLength === 0) {
          wx.showModal({
            title: "提示",
            content: "请先登录！"
          })
        } else {
          wx.navigateTo({
            url: '../userinfo/userinfo',
          })
        }
        break
      case 3:
        if (tokenLength === 0) {
          wx.showModal({
            title: "提示",
            content: "请先登录！"
          })
        } else {
          wx.navigateTo({
            url: '../orderQuery/orderQuery',
          })
        }
        break
      case 4:
        if (tokenLength === 0) {
          wx.showModal({
            title: "提示",
            content: "请先登录！"
          })
        } else {
          wx.navigateTo({
            url: '../history/history',
          })
        }
        break
      case 5:
        if (tokenLength === 0) {
          wx.showModal({
            title: "提示",
            content: "请先登录！"
          })
        } else {
          wx.navigateTo({
            url: '../hotBooks/hotBooks',
          })
        }
        break
      case 6:
        if (tokenLength === 0) {
          wx.showModal({
            title: "提示",
            content: "请先登录！"
          })
        } else {
          wx.navigateTo({
            url: '../borrowState/borrowState',
          })
        }
        break
      case 7:
        break
      case 8:
        break
    }
  },

  onLoad: function () {

  }
})
